﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using PBOffice.Models;

public partial class Admin_Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;
        //string name = (Session["username"] as Staff).StfName;
        string order = new UserDeskFunManager().GetOrderByUserId("admin");
        if (order != null)
        {
            string[] orderArry = order.Split(new char[] { ',' });
            List<DeskFun> list = new List<DeskFun>();
            foreach (string item in orderArry)
            {

                DeskFun desk = new DeskFun();
                desk.DisplayOrder = Convert.ToInt32(item);
                DeskFun de = new DeskFunManager().GetDeskFunByOrder(Convert.ToInt32(item));
                desk.FunId = de.FunId;
                desk.FunPath = de.FunPath;
                desk.Title = de.Title;
                list.Add(desk);
            }

            lvDesktop.DataSource = list;
            lvDesktop.DataBind();
        }


    }


    protected void lvDesktop_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        DeskFun plugin = e.Item.DataItem as DeskFun;
        string physicalPath = Server.MapPath(plugin.FunPath);
        if (System.IO.File.Exists(physicalPath))//存在控件，加载它
        {
            e.Item.FindControl("pContent").Controls.Add(LoadControl(plugin.FunPath));
        }
    }



    protected void btnReturn_Click(object sender, EventArgs e)
    {
        //string name = (Session["username"] as Staff).StfName;
        string order = new UserDeskFunManager().GetOrderByUserId("admin");
        string[] orderArry = order.Split(new char[] { ',' });
        List<DeskFun> list = new List<DeskFun>();
        foreach (string item in orderArry)
        {

            DeskFun desk = new DeskFun();
            desk.DisplayOrder = Convert.ToInt32(item);
            DeskFun de = new DeskFunManager().GetDeskFunByOrder(Convert.ToInt32(item));
            desk.FunId = de.FunId;
            desk.FunPath = de.FunPath;
            desk.Title = de.Title;
            list.Add(desk);
        }

        lvDesktop.DataSource = list;
        lvDesktop.DataBind();
    }
}